package com.ruoyi.records.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.records.domain.BorrowRecords;
import com.ruoyi.records.service.IBorrowRecordsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 图书借阅管理Controller
 * 
 * @author ruoyi
 * @date 2025-06-07
 */
@Controller
@RequestMapping("/library/records")
public class BorrowRecordsController extends BaseController
{
    private String prefix = "library/records";

    @Autowired
    private IBorrowRecordsService borrowRecordsService;

    @RequiresPermissions("library:records:view")
    @GetMapping()
    public String records()
    {
        return prefix + "/records";
    }

    /**
     * 查询图书借阅管理列表
     */
    @RequiresPermissions("library:records:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BorrowRecords borrowRecords)
    {
        startPage();
        List<BorrowRecords> list = borrowRecordsService.selectBorrowRecordsList(borrowRecords);
        return getDataTable(list);
    }

    /**
     * 导出图书借阅管理列表
     */
    @RequiresPermissions("library:records:export")
    @Log(title = "图书借阅管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BorrowRecords borrowRecords)
    {
        List<BorrowRecords> list = borrowRecordsService.selectBorrowRecordsList(borrowRecords);
        ExcelUtil<BorrowRecords> util = new ExcelUtil<BorrowRecords>(BorrowRecords.class);
        return util.exportExcel(list, "图书借阅管理数据");
    }

    /**
     * 新增图书借阅管理
     */
    @RequiresPermissions("library:records:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存图书借阅管理
     */
    @RequiresPermissions("library:records:add")
    @Log(title = "图书借阅管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BorrowRecords borrowRecords)
    {
        return toAjax(borrowRecordsService.insertBorrowRecords(borrowRecords));
    }

    /**
     * 修改图书借阅管理
     */
    @RequiresPermissions("library:records:edit")
    @GetMapping("/edit/{recordId}")
    public String edit(@PathVariable("recordId") Long recordId, ModelMap mmap)
    {
        BorrowRecords borrowRecords = borrowRecordsService.selectBorrowRecordsByRecordId(recordId);
        mmap.put("borrowRecords", borrowRecords);
        return prefix + "/edit";
    }

    /**
     * 修改保存图书借阅管理
     */
    @RequiresPermissions("library:records:edit")
    @Log(title = "图书借阅管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BorrowRecords borrowRecords)
    {
        return toAjax(borrowRecordsService.updateBorrowRecords(borrowRecords));
    }

    /**
     * 删除图书借阅管理
     */
    @RequiresPermissions("library:records:remove")
    @Log(title = "图书借阅管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(borrowRecordsService.deleteBorrowRecordsByRecordIds(ids));
    }
}
